import 'package:flutter/material.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/common_utils.dart';

/**
 * Created by guoshuyu
 * Date: 2018-07-26
 */
class QuhuiCommonOptionWidget extends StatelessWidget {
  final List<QuhuiOptionModel> otherList;

  final OptionControl control;

  QuhuiCommonOptionWidget(this.control, {this.otherList});

  _renderHeaderPopItem(List<QuhuiOptionModel> list) {
    return new PopupMenuButton<QuhuiOptionModel>(
      child: new Icon(MIcon.more),
      onSelected: (model) {
        model.selected(model);
      },
      itemBuilder: (BuildContext context) {
        return _renderHeaderPopItemChild(list);
      },
    );
  }

  _renderHeaderPopItemChild(List<QuhuiOptionModel> data) {
    List<PopupMenuEntry<QuhuiOptionModel>> list = new List();
    for (QuhuiOptionModel item in data) {
      list.add(PopupMenuItem<QuhuiOptionModel>(
        value: item,
        child: new Text(item.name),
      ));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    List<QuhuiOptionModel> list = [
      new QuhuiOptionModel("",
          "", (model) {
//        CommonUtils.launchOutURL(control.url, context);
      }),
      new QuhuiOptionModel("",
          "", (model) {
        CommonUtils.copy(control.url ?? "", context);
      }),
      new QuhuiOptionModel("",
          "", (model) {
//        Share.share(
//            QuhuiLocalizations.i18n(context).option_share_title + control.url ??
//                "");
      }),
    ];
    if (otherList != null && otherList.length > 0) {
      list.addAll(otherList);
    }
    return _renderHeaderPopItem(list);
  }
}

class OptionControl {
  String url = QuhuiConstant.app_default_share_url;
}

class QuhuiOptionModel {
  final String name;
  final String value;
  final PopupMenuItemSelected<QuhuiOptionModel> selected;

  QuhuiOptionModel(this.name, this.value, this.selected);
}
